package com.lanou.controller;


import com.lanou.bean.Owner;
import com.lanou.bean.ReclamationOrder;
import com.lanou.bean.Scrap;
import com.lanou.service.OwnerService;
import com.lanou.service.ReclamationOrderService;
import com.lanou.service.ScrapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RestController
public class ReclamationOrderController {

    @Autowired
    private OwnerService ownerService;

    @Autowired
    private ScrapService scrapService;

    @Autowired
    private ReclamationOrderService reclamationOrderService;

    @RequestMapping("/getOwnerName")
    public List<Owner> getOwnerName(){
        List<Owner> owners = ownerService.getOwnerName();
        System.out.println("获取到业主的姓名信息-------"+owners);
        return owners;
    }

    @RequestMapping("/getScrap")
    public List<Scrap> getScrap(){
        List<Scrap> scraps = scrapService.getScrap();
        System.out.println("获取到的垃圾信息---------"+scraps);
        return scraps;
    }



    @RequestMapping("/addrecord")
    public int addrecord(String record){
        String[] splits = record.split("/");
        ReclamationOrder order=new ReclamationOrder();
        order.setOwnerId(splits[0]);
        order.setScrapCode(splits[1]);
        order.setUnit(splits[2]);
        order.setCreateTime(new Date());
        order.setUpdateTime(new Date());
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyyMMddHH:mm:ss");
        String date = simpleDateFormat.format(new Date());
        order.setOrderNo("R"+date+splits[1]);
        order.setRdStatus("rd_0");
        order.setScStatus("sc_0");
        int result = reclamationOrderService.insertSelective(order);
        return result;
    }


    @RequestMapping("/getRecOrdList")
    public List<ReclamationOrder> getRecOrdList(){

        List<ReclamationOrder> recOrdList = reclamationOrderService.getRecOrdList();
        System.out.println("展示所有的订单列表----------"+recOrdList);

        return recOrdList;
    }


    @RequestMapping("/cancelOrder")
    public int cancelOrder(String data){
        String[] split = data.split("/");
        System.out.println("获取的状态和订单编号---------"+split[0]+" "+split[1]);
        ReclamationOrder order=new ReclamationOrder();
        System.out.println("-----"+order);
        order.setOrderNo(split[0]);
        order.setScStatus(split[1]);
        order.setUpdateTime(new Date());
        System.out.println("order信息-------"+order);

        int result = reclamationOrderService.cancelOrder(order);
        System.out.println("取消订单结果---------"+result);
        return result;
    }


}
